Assuming that the url provided is wrong, the Got module raises a HTTPError, how do I catch the error? Try catch doesn't work
const got = require('got');
got(`https://www.wrongurl.com`)
.then(response => {
//do stuff
})
I would use
got(...).then(
response => { /* handle good response here */},
error => { /* handle error here */ }
)
Simple .catch(() => { ... }) may catch an error in .then(response... part as well, that's not what you expect.
Also see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then for reference.